package com.bbg.amyam.web.util.view;

import java.io.File;
import java.io.IOException;
import java.util.Collection;

import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.bbg.amyam.web.util.menu.MenuItem;

public class WebflowViewFilesCopier extends ViewFilesCopier{

	private static final Log log = LogFactory.getLog(WebflowViewFilesCopier.class);
	
	public WebflowViewFilesCopier(MenuItem menuItem, File templateDir, File destDir,
			File viewRootcDir) {
		super(menuItem,templateDir,destDir,viewRootcDir);
	}

	public void doCopy(boolean overwrite) {
		Collection<File> files = FileUtils.listFiles(this.templateDir, new String[] {"*"}, false );
		for (File file:files){
			String fileName = file.getName();
			File destFile=new File(this.destDir,fileName);
			if(destFile.exists()){
				if(overwrite){
					destFile.delete();
				}else{
					continue;
				}
			}
			
			try {
				FileUtils.copyFile(file, destFile);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				log.error(e.getMessage());
			}
		}
		
	}
}
